<?php
/**
 * @author yuanyitian
 * @date 2024/10/22 17:27
 */

namespace api\wechat;

class setting
{
    //获取轮播图
    public function getImg()
    {
        $con = con();
        $data = mysqli_query($con, "select * from setting where id in (4,5) ");
        $data = mysqli_fetch_all($data, true);
        mysqli_close($con);


        $background = '';
        $swiper = [];
        for ($i = 0; $i < count($data); $i++) {
            if (!empty($data[$i]['value_1'])) {
                if ($data[$i]['id'] == 4) {//轮播图
                    $swiper = explode(',', $data[$i]['value_1']);
                } else {//背景图
                    $background = $data[$i]['value_1'];
                }
            }
        }


        return out_right([
            'background'=>$background,
            'swiper'=>$swiper
        ]);
    }

    //获取跑马灯数据
    public function getLight(){
        $con = con();
        $data=mysqli_query($con,"select * from setting where id=9");
        $data = mysqli_fetch_all($data, true);
        mysqli_close($con);
        if(count($data)===0){
            return out_error('缺少设置数据！请联系技术！');
        }else{
            return out_right($data[0]['value_1']);
        }
    }

    //获取配送设置
    public function getSend(){
        $con = con();
        $data=mysqli_query($con,"select * from setting where id in (6,7) order by `id` ASC ");
        $data=mysqli_fetch_all($data, true);
        mysqli_close($con);
        if(count($data)===0){
            return out_error('缺少设置数据！');
        }else{
            return out_right([
                'send_status'=>(bool)$data[0]['value_1'],
                'send_price'=>$data[1]['value_1'],
            ]);
        }
    }

    //获取自定义区域设置
    public function getArea(){
        $con = con();
        $data=mysqli_query($con,"select * from setting where id in (15,16,17,18) order by `id` ASC ");
        $data = mysqli_fetch_all($data, true);
        mysqli_close($con);
        if(count($data)===0){
            return out_error('缺少设置数据！请联系技术！');
        }else{
            return out_right([
                'area_1_open'=>(bool)$data[0]['value_1'],
                'area_1_title'=>$data[1]['value_1'],
                'area_2_open'=>(bool)$data[2]['value_1'],
                'area_2_title'=>$data[3]['value_1'],
            ]);
        }
    }

}